package main

import (
	"fmt"
	. "local/algorithm/util"
	bst "local/datastructure/tree/binarySearchTree"
)

func main() {
	t := bst.Generate([]int{10, 5, 15})
	r := rightSideView(t)
	fmt.Println(r)
	r = rightSideView2(t)
	fmt.Println(r)
}

func rightSideView(root *TreeNode) []int {
	if root == nil {
		return []int{}
	}

	list := []int{}
	size := 1
	q := []*TreeNode{}
	q = append(q, root)
	for len(q) != 0 {
		node := q[0]
		q = q[1:]
		size--
		if node.Left != nil {
			q = append(q, node.Left)
		}

		if node.Right != nil {
			q = append(q, node.Right)
		}

		if size == 0 {
			list = append(list, node.Val)
			size = len(q)
		}
	}
	return list
}
